package com.wc.alorithm_blue_bridge._数据结构.单调队列.Q1375;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.*;

/**
 * @Author congge
 * @Date 2023/11/3 21:49
 * m计划
 * https://www.lanqiao.cn/problems/1375/learning/?page=1&first_category_id=1&sort=students_count&second_category_id=8
 */
public class Main {
    public static void main(String[] args) {
        ArrayDeque<Integer> queue = new ArrayDeque<>();
        Input sc = new Input();

        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }
        int[] ans = new int[n - m + 1];
        Main main = new Main();
        for (int i = 0; i < m; i++) {
            main.push(array[i], queue);
        }
        ans[0] = main.front(queue);
        for (int i = m; i < n; i++) {
            main.pop(array[i - m], queue);
            main.push(array[i], queue);
            ans[i - m + 1] = main.front(queue);
        }

        for (int num : ans) {
            System.out.println(num);
        }
    }

    public void push(int val, ArrayDeque<Integer> queue) {
        while (!queue.isEmpty() && val < queue.getLast()) {
            queue.removeLast();
        }
        queue.addLast(val);
    }

    public void pop(int val, ArrayDeque<Integer> queue) {
        if (!queue.isEmpty() && queue.getFirst() == val) {
            queue.removeFirst();
        }
    }

    public int front(ArrayDeque<Integer> queue) {
        return queue.getFirst();
    }

    static class Input {
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

        public int nextInt() {
            try {
                in.nextToken();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return (int) in.nval;
        }
    }
}
